# from django_filters import rest_framework as filters
from django_filters import filters, DateFilter, DateTimeFilter
from django_filters.rest_framework.filterset import FilterSet
from api.models import Order,OrderDetail

class OrderFilter(FilterSet):
    order_id = filters.CharFilter(field_name='order_id')
    customer = filters.CharFilter(field_name='customer')
    status = filters.CharFilter(field_name='status')
    order_date = filters.DateFromToRangeFilter()
    # # 开始时间：查询 created_at >= start_time
    # start_time = DateTimeFilter(
    #     field_name='creation_date', 
    #     lookup_expr='gte',  # gte = greater than or equal
    #     label='开始时间',
    #     help_text='格式: YYYY-MM-DD HH:MM:SS'
    # )
    # # 结束时间：查询 creation_date <= end_time
    # end_time = DateTimeFilter(
    #     field_name='creation_date', 
    #     lookup_expr='lte',  # lte = less than or equal
    #     label='结束时间',
    #     help_text='格式: YYYY-MM-DD HH:MM:SS'
    # )

    class Meta:
        model = Order
        fields = ['customer', 'status', 'order_date','order_id']

# 订单明细表 - *
class BrandOrderDetails(FilterSet):
    order_id = filters.CharFilter(field_name='order_id')
    detail_id = filters.CharFilter(field_name='detail_id')
    product_id = filters.CharFilter(field_name='product_id')
    product_name = filters.CharFilter(field_name='product_name')

    class Meta:
        model = OrderDetail
        fields = ['order_id', 'detail_id', 'product_id','product_name']